import express from "express";
import path from "path";
import { createProxyMiddleware } from "http-proxy-middleware";

const options = {
  targetProject: "../gis-baohe",
  targetServer: "https://m.xinwangzn.com:8081",
  apiPrefix: "/xw-microservice",
  port: 3000,
};

const app = express();

app.listen(options.port, () => {
  console.log("server running at http://localhost:" + options.port);
});

app.use("/", express.static(path.resolve(options.targetProject)));

app.use(
  options.apiPrefix,
  createProxyMiddleware({
    target: options.targetServer,
    changeOrigin: true,
    ws: true,
    secure: true,
    pathRewrite: {
      [options.apiPrefix]: options.apiPrefix,
    },
  }),
);
